<?=isset($header) ? $header : ''?>
<script src="/js/adduser.js"></script>


<div id="content">
	<div class="form_style">
	<div class="title">
           <h5>用戶添加</h5>
    </div>
		<form method="post" action="<?=site_url('/user/add_submit')?>" id="userinfo">
			<table border="1">
			  <tbody><tr>
			    <th width="80">用戶ID：</th>
			    <td>
			      <input type="text" id="user" name="user">
			      (注：用戶ID為登錄帳號)
			    </td>
			  </tr>
			  
			  <tr>
			    <th>用戶姓名：</th>
			    <td><input type="text" id="name" name="name"></td>
			  </tr>

			  <tr>
			    <th>用戶密碼：</th>
			    <td><input type="password" id="password" name="password">(注：用戶密碼為登錄密碼)</td>			    
			  </tr>

			  <tr>
			    <th>E-Mail：</th>
			    <td><input type="text" id="email" name="email"></td>			    
			  </tr>

			  <tr>
			    <th>手機：</th>
			    <td><input type="text" id="phone" name="phone"></td>			    
			  </tr>


			  <tr>
			    <th>所屬部門：</th>
			    <td>
			    	<select name="department_id" id="department_id">
					<? foreach($department as $key=>$val){?>
			    		<option value="<?=$val->department_id?>"><?=$val->department_name?></option>
					<?
					}
					?>
					</select>
			    </td>
			  </tr>
			  <tr>
			    <th>所屬角色：</th>
			    <td>
			    	<select name="role_id" id="role_id">
			    	<? foreach($role as $key=>$val){?>
			    		<option value="<?=$val->role_id?>"><?=$val->role_name?></option>
					<?
					}
					?>
					</select>
			    
			    (注：用戶擁有角色所具有的權限)</td>
			             
			  </tr>
			  
			  <tr>
			    <td></td>
			    <td class="last_save">
			    	<input type="submit" id="submit" onclick="return checkadduser();" value="確定" class="input_background">
			   		<input type="reset" value="重置" class="input_background"></td>
			  </tr>
			</tbody></table>
		</form>
	</div>
</div>



<script>
	$("document").ready(function(){


	$("#user").blur(function(){
		
		$.post("/user/get_user", { user: $("#user").val() },
		 function(data) {

		   if(data=='error'){
		   		alert('重複了');
		   		$("#submit").css("display","none");
		   		$("#user").val('');
		   }else{
		   	$("#submit").css("display","");
		   }

		 });
	});

	$("#name").blur(function(){
		
		$.post("/user/get_user_name", { name: $("#name").val() },
		 function(data) {

		 	//alert(data);

		   if(data=='error'){
		   		$("#name").val('');
		   		alert('重複了');
		   		$("#submit").css("display","none");
		   }else{
		   		$("#submit").css("display","");
		   }
		 });
	});

});
</script>
<?=isset($footer) ? $footer : ''?>